﻿<Window x:Class="Samurai.Client.MainWindow"
        x:Name="Me"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:Controls="clr-namespace:Samurai.Client.Controls"        
        xmlns:l="clr-namespace:UIControls;assembly=UIControls"
        WindowStartupLocation="CenterScreen"
        WindowStyle="SingleBorderWindow"
        WindowState="Maximized"
        Title="Samurai - The Movie Warrior"
        MinHeight="600"
        MinWidth="800" 
        Icon="/Samurai.Client;component/Images/strawhatsamurai.gif" 
        Loaded="MeLoaded">  

  <Border Margin="5" BorderBrush="Black" BorderThickness="2" CornerRadius="5">

    <Grid x:Name="MasterRegion" Background="{DynamicResource OrangeGradientBrush}">

      <Grid.RowDefinitions>
        <RowDefinition Height="70" />
        <RowDefinition Height="*" />
        <RowDefinition Height="30" />
      </Grid.RowDefinitions>

      <Grid Grid.Row="0" x:Name="ToolRegion" Background="{x:Null}">
        <StackPanel x:Name="LeftToolRegion" Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="5">
          <ComboBox Style="{StaticResource ImageComboBox}" ItemsSource="{Binding ElementName=Me, Path=DataContext.Genres}" SelectedItem="{Binding ElementName=Me, Path=DataContext.SelectedGenreItem}" x:Name="ComboBoxGenres" Margin="5" Width="100" />
        </StackPanel>

        <StackPanel x:Name="CenterToolRegion" Orientation="Horizontal" MinWidth="150" MinHeight="35" HorizontalAlignment="Center" VerticalAlignment="Center">
          <l:SearchTextBox Search="SearchTextBoxSearched" Height="21" Width="150" SearchMode="Delayed" Padding="0" />
        </StackPanel>

        <StackPanel x:Name="RightToolRegion" Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="5">

          <Button x:Name="RefreshButton" Style="{StaticResource GlassButton}" Width="48" Height="48" Background="#FF329448"  Margin="2" HorizontalAlignment="Center" VerticalAlignment="Center"
              Command="{Binding ElementName=Me, Path=DataContext.RefreshMoviesCommand}" ToolTip="Click here to reload all Movies.">
            <Image Width="32" Height="32" Source="Images\refresh32x32.gif"/>
          </Button>

          <Button x:Name="ShowRepositoryButton" Style="{StaticResource GlassButton}" Width="48" Height="48" Background="#FF329448" Margin="2" HorizontalAlignment="Center" VerticalAlignment="Center"
              Command="{Binding ElementName=Me, Path=DataContext.ShowRepositoryCommand}" ToolTip="Click here view Movie Repository.">
            <Image Width="32" Height="32" Source="Images\repository32x32.gif"/>
          </Button>

          <Button Style="{StaticResource GlassButton}" Width="48" Height="48" Margin="2" HorizontalAlignment="Center" VerticalAlignment="Center"
              Command="{Binding ElementName=Me, Path=DataContext.ExitCommand}" ToolTip="Click here to Exit.">
            <Image Width="32" Height="32" Source="Images\quit32x32.png"/>
            <Button.Background>
              <SolidColorBrush />
            </Button.Background>
          </Button>

          <Button FontWeight="Bold" Style="{StaticResource GlassButton}" Width="48" Height="48" Margin="2" HorizontalAlignment="Center" VerticalAlignment="Center"
                Command="{Binding ElementName=Me, Path=DataContext.ExportCommand}" ToolTip="Click here to Export.">
            E
            <Button.Background>
              <SolidColorBrush />
            </Button.Background>
          </Button>

          <Button FontWeight="Bold" Style="{StaticResource GlassButton}" Width="48" Height="48" Margin="2" HorizontalAlignment="Center" VerticalAlignment="Center"
                Command="{Binding ElementName=Me, Path=DataContext.ImportCommand}" ToolTip="Click here to Export.">
            I
            <Button.Background>
              <SolidColorBrush />
            </Button.Background>
          </Button>

        </StackPanel>
      </Grid>

      <Controls:Spinner Visibility="{Binding IsWaiting, Converter={StaticResource BooleanToVisibilityConverter}}" Panel.ZIndex="1000" Grid.Row="1" />

      <Grid Opacity="{Binding IsWaiting, Converter={StaticResource IsWaitingToOpacityConverter}}" x:Name="ThumbnailsRegion" Grid.Row="1" Background="{x:Null}">
        <ScrollViewer VerticalScrollBarVisibility="Auto">
          <ItemsControl Visibility="Visible" BorderBrush="Gray" BorderThickness="1" ItemsSource="{Binding Movies}" x:Name="ImageList" ScrollViewer.HorizontalScrollBarVisibility="Disabled" Background="{x:Null}">
            <ItemsControl.ItemTemplate>
              <DataTemplate>
                <Border Margin="5" BorderBrush="Black" Width="300" Height="150" BorderThickness="2" CornerRadius="5">
                  <Grid >
                    <Grid.ColumnDefinitions>
                      <ColumnDefinition Width="100" />
                      <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                      <RowDefinition Height="*" />
                      <RowDefinition Height="*" />
                      <RowDefinition Height="0.66*" />
                    </Grid.RowDefinitions>

                    <StackPanel x:Name="RegionActions" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" FlowDirection="RightToLeft" Orientation="Horizontal" Grid.Row="2" Grid.Column="1">


                      <Button Style="{StaticResource RectangleGlassButton}" Width="37" Height="37" Margin="2" HorizontalAlignment="Center" VerticalAlignment="Center"
                              Command="{Binding ElementName=Me, Path=DataContext.NotAMovieCommand}"
                              CommandParameter="{Binding}"
                              ToolTip="Click here to delete">
                        <Image Width="32" Height="32" Source="Images\delete32x32.png"/>
                      </Button>
                      
                      <Button Visibility="Collapsed" Style="{StaticResource RectangleGlassButton}" Width="39" Height="22" Margin="2" HorizontalAlignment="Center" VerticalAlignment="Center"
                              Command="{Binding ElementName=Me, Path=DataContext.EditMovieCommand}"
                              CommandParameter="{Binding}"
                              ToolTip="Click here to edit">
                        Edit
                      </Button>

                      <Button Background="WhiteSmoke" Style="{StaticResource RectangleGlassButton}" Width="39" Height="22" Margin="2" HorizontalAlignment="Center" VerticalAlignment="Center"
                              Command="{Binding ElementName=Me, Path=DataContext.OpenDirectoryCommand}"
                              CommandParameter="{Binding}"
                              ToolTip="{Binding Path}">
                        <Image Width="34" Height="17" Source="Images\folder34x17.gif"/>
                      </Button>

                      <Button Background="Orange" Style="{StaticResource RectangleGlassButton}" Width="39" Height="22" Margin="2" HorizontalAlignment="Center" VerticalAlignment="Center"
                              Command="{Binding ElementName=Me, Path=DataContext.GotoUrlCommand}"
                              CommandParameter="{Binding Url}"
                              ToolTip="Imdb">
                        <Image Width="34" Height="17" Source="Images\IMDB_34x17.png"/>
                      </Button>
                    </StackPanel>


                    <Image Grid.Row="0" Grid.Column="0" Grid.RowSpan="3" HorizontalAlignment="Center" VerticalAlignment="Center" Source="{Binding Image, Converter={StaticResource ByteArrayToImageConverter}}"  />


                    <StackPanel x:Name="RegionMovieTitle" Orientation="Vertical" Grid.Row="0" Grid.Column="1">
                      <TextBlock Foreground="Yellow" Background="Black" Margin="5" HorizontalAlignment="Left" VerticalAlignment="Center" FontSize="12" TextTrimming="CharacterEllipsis" Width="175" ToolTip="{Binding MovieTitleWithYear}" Text="{Binding MovieTitleWithYear}" FontFamily="Arial" FontWeight="Bold" />
                      <Controls:RatingsControl x:Name="Ratings"
                   BackgroundColor="White"
                   StarForegroundColor="Orange"
                   StarOutlineColor="DarkGray"
                   Value="{Binding Rating}"
                   ToolTip="{Binding Rating}"
                   NumberOfStars="10"
                   Margin="5" />
                    </StackPanel>

                    <ItemsControl Grid.Row="1" Grid.Column="1" ItemsSource="{Binding Genres}" HorizontalAlignment="Left" VerticalAlignment="Center">

                      <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                          <WrapPanel Orientation="Horizontal" />
                        </ItemsPanelTemplate>
                      </ItemsControl.ItemsPanel>

                      <ItemsControl.ItemTemplate>
                        <DataTemplate>
                          <Image Margin="3" ToolTip="{Binding}" Width="32" Height="32" Source="{Binding Converter={StaticResource GenreTitleToImageConverter}}" />
                        </DataTemplate>
                      </ItemsControl.ItemTemplate>
                    </ItemsControl>
                  </Grid>
                </Border>
              </DataTemplate>
            </ItemsControl.ItemTemplate>
            <ItemsControl.ItemsPanel>
              <ItemsPanelTemplate>
                <WrapPanel />
              </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
          </ItemsControl>
        </ScrollViewer>
      </Grid>

      <Grid x:Name="ActivityRegion" Background="OrangeRed" Grid.Row="2">

        <TextBlock Text="{Binding CurrentActivity}" Foreground="White" Margin="10,0,10,0" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="16" />

      </Grid>

    </Grid>

  </Border>

</Window>